package com.loc;

import android.content.Context;
import android.os.SystemClock;
import android.text.TextUtils;
import org.json.JSONObject;

/* compiled from: AAIDManager.java */
/* loaded from: classes2.dex */
public class ac {
    private static ac a = null;
    private static boolean b = false;
    private static boolean c = false;
    private Context d;

    private ac(Context context) {
        this.d = context;
    }

    public static ac a(Context context) {
        if (a == null) {
            synchronized (ac.class) {
                if (a == null) {
                    a = new ac(context);
                }
            }
        }
        return a;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void b() {
        try {
            if (b) {
                b = false;
                return;
            }
            b = true;
            aa aaVar = new aa(this.d);
            new bo();
            bu a2 = bo.a(aaVar);
            if (a2 != null) {
                JSONObject jSONObject = new JSONObject(x.a(ab.a(a2.a, x.c("YWDR1a2R2WEd0M3RXdHRocg==").getBytes())));
                if (jSONObject.optBoolean("suc")) {
                    y.f(this.d, aaVar.a);
                    y.g(this.d, aaVar.b);
                    y.h(this.d, aaVar.c);
                    y.i(this.d, aaVar.d);
                    y.j(this.d, aaVar.e);
                    y.k(this.d, aaVar.f);
                    y.l(this.d, aaVar.g);
                    y.b(this.d, aaVar.i);
                    y.m(this.d, aaVar.h);
                    y.a(this.d, SystemClock.elapsedRealtime());
                    String optString = jSONObject.optString("aaid", "");
                    String optString2 = jSONObject.optString("resetToken", "");
                    String optString3 = jSONObject.optString("uabc", "");
                    if (!TextUtils.isEmpty(optString)) {
                        y.c(this.d, optString);
                    }
                    if (!TextUtils.isEmpty(optString2)) {
                        y.e(this.d, optString2);
                    }
                    if (!TextUtils.isEmpty(optString3)) {
                        y.d(this.d, optString3);
                    }
                }
            }
            b = false;
        } catch (Throwable unused) {
            b = false;
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void c() {
        try {
            if (c) {
                c = false;
                return;
            }
            c = true;
            ad adVar = new ad(this.d);
            new bo();
            bu a2 = bo.a(adVar);
            if (a2 != null) {
                JSONObject jSONObject = new JSONObject(x.a(ab.a(a2.a, x.c("YWDR1a2R2WEd0M3RXdHRocg==").getBytes())));
                if (jSONObject.optBoolean("suc")) {
                    y.f(this.d, adVar.a);
                    y.g(this.d, adVar.b);
                    y.h(this.d, adVar.c);
                    y.i(this.d, adVar.d);
                    y.j(this.d, adVar.e);
                    y.k(this.d, adVar.f);
                    y.l(this.d, adVar.g);
                    y.b(this.d, adVar.i);
                    y.m(this.d, adVar.h);
                    y.a(this.d, SystemClock.elapsedRealtime());
                    String optString = jSONObject.optString("aaid", "");
                    String optString2 = jSONObject.optString("resetToken", "");
                    String optString3 = jSONObject.optString("uabc", "");
                    if (!TextUtils.isEmpty(optString)) {
                        y.c(this.d, optString);
                    }
                    if (!TextUtils.isEmpty(optString2)) {
                        y.e(this.d, optString2);
                    }
                    if (!TextUtils.isEmpty(optString3)) {
                        y.d(this.d, optString3);
                    }
                }
            }
            c = false;
        } catch (Throwable unused) {
            c = false;
        }
    }

    public final String a() {
        cr a2;
        cs csVar;
        String str = "";
        try {
            if (z.d) {
                str = y.c(this.d);
                long d = y.d(this.d);
                long elapsedRealtime = SystemClock.elapsedRealtime();
                if (TextUtils.isEmpty(str)) {
                    a2 = cr.a();
                    csVar = new cs() { // from class: com.loc.ac.1
                        @Override // com.loc.cs
                        public final void a() {
                            ac.this.b();
                        }
                    };
                } else if (elapsedRealtime - d > z.b) {
                    a2 = cr.a();
                    csVar = new cs() { // from class: com.loc.ac.2
                        @Override // com.loc.cs
                        public final void a() {
                            ac.this.c();
                        }
                    };
                }
                a2.b(csVar);
            }
        } catch (Throwable unused) {
        }
        return str;
    }
}
